<template lang=pug>
    div
        section
            label 标题
            input(v-model="product.ej_good_title")
        section
            label 描述
            input(v-model="product.ej_good_desc")
        section
            form(action="fileUpload",method="post",enctype="multipart/form-data",ref="form")
                label 图片
                input(@change="upload",name="file",type="file", accept="image/*", multiple)
        section
            label 租借价格
            input(v-model="product.ej_good_rent_price")
        section
            label 租借单位
            input(v-model="product.ej_good_rent_unit")
        section
            label 购买原价
            input(v-model="product.ej_good_original_price")
        section
            label 购买日期
            input(v-model="product.ej_good_purchasing_date")
        section
            span 取货方式
            select(v-model="product.ej_good_pickup_mode_id")
                option(v-for="item in pickup",:key="item.ej_good_pickup_mode_id",v-text="item.ej_good_pickup_mode_name",:value="item.ej_good_pickup_mode_id")
        section
            label 租借时间
            input(v-model="product.ej_good_rent_time")
        section
            span 协议类型
            select(v-model="product.ej_good_deal_id")
                option(v-for="item in deal",:key="deal.ej_good_deal_id",v-text="item.ej_good_deal_content",:value="item.ej_good_deal_id")
        section
            label 协议内容
            input(v-model="product.ej_good_deal_content")
        section
            label 所在位置
            input(v-model="product.ej_good_contact_address")
        section
            label 联系方式
            input(v-model="product.ej_good_contact_phone")
        section
            button(@click="submit") 提交
</template>

<script type="es6">
    export default {
        name: 'publish',
        data () {
            return {
                product:{},
                deal:[],
                pickup:[]
            }
        },
        methods:{
            submit(){
                console.log(this.product)
                this.$http.post(this.$config.basePath+'/good/save','good='+JSON.stringify(this.product),{
                    headers:{
                        'Content-Type':'application/x-www-form-urlencoded'
                    }
                }).then((response)=>{
                    console.log(response)
                })
            },
            upload(ev){
                console.dir(this.$refs.form)
                let FileForm = new FormData(this.$refs.form)
                console.log(FileForm)
                let self = this
                console.log(ev.target.files[0])
                this.$http.post(this.$config.fileBasePath+'/save',FileForm,{
                    headers:{
                        'Content-Type':'multipart/form-data'
                    }
                }).then(response=>{
                    self.product.ej_good_picture_url = response.data
                    console.log(response.data)
                })
            }
        },
        mounted (){
            this.$http.get(this.$config.basePath+'/deal/get').then((response)=>{
                console.log('deal=',response)
                this.deal = response.data.data.list
            })
            this.$http.get(this.$config.basePath+'/pickup/get').then((response)=>{
                console.log('pickup=',response)
                this.pickup = response.data.data.list
            })

        },
        components: {}
    }
</script>

<style lang="stylus">
</style>
